package k8s

import (
	"crypto/tls"
	"net/http"
	"os"

	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/clientcmd"
)

// TLS --kubeconfig
func getConfig() *rest.Config {
	// TODO k8s 配置文件的路径
	var kubeconfigPath = "/Users/jasper/work/config/uwintech/k8s-55.conf"

	kubeconfig, err := os.ReadFile(kubeconfigPath)
	if err != nil {
		panic(err)
	}

	apiConfig, err := clientcmd.Load([]byte(kubeconfig))
	if err != nil {
		panic(err)
	}
	clientConfig := clientcmd.NewDefaultClientConfig(*apiConfig, &clientcmd.ConfigOverrides{})
	config, err := clientConfig.ClientConfig()
	if err != nil {
		panic(err)
	}
	return config
}

// Token --token
func getConfig2() *rest.Config {
	config := &rest.Config{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		},
		// TODO
		Host:        "https://TODO:6443",
		BearerToken: "TODO",
	}
	return config
}

func getClient() *kubernetes.Clientset {
	config := getConfig2()
	client, err := kubernetes.NewForConfig(config)
	if err != nil {
		panic(err)
	}
	return client
}
